package cn.edu.jxust.core.infrastructure.mapper;

import cn.edu.jxust.common.domain.entity.Air;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * @author QiuKangming
 * @since 2020-06-29
 */

public interface AirMapper extends BaseMapper<Air> {

    /**
     * 获取上一个小时上传数据的监测设备的id值
     * @param date 日期
     * @param begin 开始时间
     * @param end 结束时间
     * @return List<Integer>
     */
    @Select("SELECT DISTINCT device_id FROM t_air where create_date = #{date} AND create_time BETWEEN #{begin} AND #{end} AND is_exception = 1 AND status = 1")
    List<Integer> getLastHourDeviceIds(String date, String begin, String end);

    /**
     * 获取前一天上传PM信息监测设备的ids
     * @param date 日期
     * @param ids id集合
     * @param begin 开始时间
     * @param end 结束时间
     * @return List<Integer>
     */
    @Select({
            "<script>",
            "SELECT DISTINCT device_id FROM t_air WHERE airtype_id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')' >",
            "#{id}",
            "</foreach>",
            "AND create_date = #{date} AND create_time BETWEEN #{begin} AND #{end} AND is_exception = 1 AND status = 1",
            "</script>"
    })
    List<Integer> getLastDayPMDeviceIds(String date, @Param("ids") List<Integer> ids, String begin, String end);

}
